from tkinter import *

master = Tk()


v = StringVar()

def test(content):
    return content.isdigit()

testCMD = master.register(test)

e = Entry(master,textvariable=v,validate='key',\
          validatecommand=(testCMD,'%P')).pack()

mainloop()
